package com.ibm.workplace.wcm.cqplugin;

public class BugState {
	
	public static final BugState OPEN = new BugState("open", "Open");
	public static final BugState CLOSED = new BugState("closed", "Closed");
	public static final BugState WORKING = new BugState("working", "Working");
	public static final BugState VERIFY = new BugState("verify", "Verify");
	public static final BugState CANCELED = new BugState("canceled", "Canceled");
    public static final BugState UNKNOWN = new BugState("unknown", "");
    public static final BugState RETURNED = new BugState("returned", "Returned");
    
    //For CQ defects
    public static final BugState ASSIGNED = new BugState("assigned", "Assigned");
    public static final BugState SUBMITTED = new BugState("submitted", "Submitted");
    public static final BugState OPENED = new BugState("opened", "Opened");
    public static final BugState RESOLVED = new BugState("resolved", "Resolved");
    public static final BugState DUPLICATE = new BugState("duplicate", "Duplicate");
	
    private String code;
	private String description;
    
    private static BugState[] BUG_STATES;
    
    static {
        BUG_STATES = new BugState[] { OPEN, CLOSED, WORKING, VERIFY, CANCELED, UNKNOWN, RETURNED, ASSIGNED, SUBMITTED, OPENED, RESOLVED, DUPLICATE } ;
    }

	private BugState(String code, String description) {
		super();
		
        this.code = code;
		this.description = description;
	}
	    
    public String getCode() {
        return code;
    }
    
    public String getDescription() {
        return description;     
    }
	
	public boolean equals(Object o) {
		if (o != null && o instanceof BugState) {
			return o == this || code.equalsIgnoreCase(((BugState)o).getCode());
		} else {
			return false;
		}
	}
    
    public String toString() {
        return description; //by kevin
    }
	
    public static BugState getBugStateFromCode(String code) {
        if (code != null) {       
            for (int i = 0; i < BUG_STATES.length; i++) {
                if (BUG_STATES[i].getCode().equalsIgnoreCase(code)) {
                    return BUG_STATES[i];
                }
            }
        }
        
        return UNKNOWN;
    }
}
